using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kotonoha.Server.Utils {
    public static class StringUtilites {
        public static IEnumerable<string> CreateBegin(string s) {
            for (int i = 1; i < s.Length + 1; i++) {
                yield return (s.Substring(0, i));
            }
        }

        public static IEnumerable<string> CreateMiddle(string s) {
            for (int i = 0; i < s.Length; i++) {
                for (int j = s.Length; j > i; j--) {
                    yield return (s.Substring(i, j - i));
                }
            }
        }

        public static IEnumerable<string> CreateEnd(string s) {
            int j = 1;
            for (int i = s.Length - 1; i >= 0; i--, j++) {
                yield return s.Substring(i, j);
            }
        }

        public static string Combine(this IEnumerable<string> m) {
            return Combine(m, ", ");
        }

        public static string Combine(this IEnumerable<string> en, string delim) {
            StringBuilder builer = en.Aggregate(new StringBuilder(), (sb, s) => sb.Append(s).Append(delim));
            return builer.Length == 0 ? "" : builer.ToString(0, builer.Length - delim.Length);
        }
    }
}